clearvars -except Globaloption option

%% chow test
data = readtable('../../data/main_VAR/US_full.xlsx');
date = data.year;

startdatenum = 1793;
enddatenum = 1914;

startdate = find(date == startdatenum);
enddate = find(date == enddatenum);
T_post = length(date(startdate:enddate));

Tstart = startdate; 
Tend = enddate; 
T = Tend - Tstart + 1;

date = date(startdate:enddate);

data = data((data.year >= startdatenum - 1), :);
data = data((data.year <= enddatenum), :);

taxrevgdp = data.tau(2:end); % government tax revenue to GDP ratio
taxrevgdp0 = data.tau(1); % government tax revenue to GDP ratio
spendgdp = data.g(2:end); % government spending before interest exdp. to GDP ratio
spendgdp0 = data.g(1); % government spending before interest exp. to GDP ratio
surplusgdp = taxrevgdp - spendgdp; % primary surplus to gdp

[h,pValue1,stat1,cValue]=chowtest(ones(length(taxrevgdp),1),taxrevgdp(1:end),[3:length(taxrevgdp)-3]);
[h,pValue2,stat2,cValue]=chowtest(ones(length(spendgdp),1),spendgdp(1:end),[3:length(spendgdp)-3]);

stat1 = [(startdatenum + 2):(enddatenum - 3); stat1]';
stat2 = [(startdatenum + 2):(enddatenum - 3); stat2]';


stat1(stat1(1:end,1)==1860,2)
stat2(stat1(1:end,1)==1860,2)